import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const token = ref(null) // token
  const userInfo = ref(null) // 用户信息

  const isLogin = computed(() => !!token.value)

  const setToken = (newToken) => {
    token.value = newToken
  }

  const setUserInfo = (newUserInfo) => {
    userInfo.value = newUserInfo
  }

  return {
    token,
    userInfo,
    isLogin,
    setToken,
    setUserInfo,
  }
}, {
  unistorage: true,
})
